#include "mwlserver.h"

#include "dcmtk/dcmwlm/wldsfs.h"
#include "dcmtk/dcmwlm/wlmactmg.h"

#include <QDebug>

MwlServer::MwlServer(int port, const QString &dfPath, QObject *parent)
    : QObject{parent}, m_port(port), m_dfPath(dfPath)
{}

void MwlServer::start() {
    WlmDataSourceFileSystem dataSource;
    qInfo() << ("set datasource db to path: " + m_dfPath).toLatin1();
    dataSource.SetDfPath(m_dfPath.toLocal8Bit().data());
    OFCondition cond = dataSource.ConnectToDataSource();
    if( cond.bad() )
    {
        qFatal() << cond.text();
        return;
    }

    WlmActivityManager activityManager(&dataSource, m_port, false, false, 0, 0, 0, ASC_DEFAULTMAXPDU, EXS_Unknown, true, true, 50, DIMSE_BLOCKING, 0, 30);
    cond = activityManager.StartProvidingService();
    if( cond.bad() )
    {
        qFatal() << cond.text();
    }

    dataSource.DisconnectFromDataSource();
}
